package com.tfj.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.tfj.comm.bean.DemoCache;


/**
 * Created by hzxuwen on 2015/4/13.
 */
public class AuthPreferences {
    private static final String KEY_USER_TOKEN = "token";
    private static final String KEY_APP_USERINFO = "userinfo";
    private static final String KEY_APP_FIRST = "iffirst";
    private static final String KEY_CLIENTID = "clientid";
    private static final String KEY_SHOP = "KEY_SHOP";
    private static final String IF_BIND = "KEY_SHOP";
    public static void saveBind(String ifBind){
        saveString(IF_BIND,ifBind);
    }
    public static String getBind(){
        return getString(IF_BIND);
    }
    public static void saveShop(String shop) {
        saveString(KEY_SHOP, shop);
    }

    public static String getShop() {
        return getString(KEY_SHOP);
    }

    public static void saveClientId(String clientId) {
        saveString(KEY_CLIENTID, clientId);
    }

    public static String getClientId() {
        return getString(KEY_CLIENTID);
    }


    public static void setFirst(String ifFirst) {
        saveString(KEY_APP_FIRST, ifFirst);
    }

    public static String getFirst() {
        return getString(KEY_APP_FIRST);
    }

    public static void saveUserInfo(String userInfo) {
        saveString(KEY_APP_USERINFO, userInfo);
    }

    public static String getUserInfo() {
        return getString(KEY_APP_USERINFO);
    }

    public static void saveUserToken(String token) {
        saveString(KEY_USER_TOKEN, token);
    }

    public static String getUserToken() {
        return getString(KEY_USER_TOKEN);
    }

    private static void saveString(String key, String value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putString(key, value);
        editor.commit();
    }

    private static String getString(String key) {
        return getSharedPreferences().getString(key, null);
    }

    static SharedPreferences getSharedPreferences() {
        return DemoCache.getContext().getSharedPreferences("Demo", Context.MODE_PRIVATE);
    }
}
